[ << previous ] [ index ] [ next >> ]

Regular Expression


This module is available only with the Toolkit.

Regular Expressions are patterns used to process text. These patterns allow you to make a comparison between a pattern and a text string and then manipluate it.

There are two types of major regex syntax: POSIX and Perl (there are a few more syntaxes, but these are the two that are supported directly in PHP).

Regular expressions are used for complex string manipulation. PHP uses the POSIX extended and PERL regular expression. No external libraries are needed to build this extension.

The POSIX radio button -- It allows to select the POSIX syntax.

The PERL radio button -- It allows to select the POSIX syntax.

The example pattern is like: "^([a-zA-Z]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z]{2,3})$"

POSIX and PERL differ in the symbols used to represent sets of characters.Where in POSIX you would use the symbol "[:digit:]" to represent all numeric characters you would use "\d" in Perl.

This example is based on POSIX: "^" -- start matching from the beginning of the string "([a-zA-Z]+)" -- find at least one character or more that contain the characters "a to z" (lowercase) and/or "A-Z" (uppercase), store this subpattern in the matching register "@" -- match this character, no special significance "([a-zA-Z0-9\-]+)" -- same as the subpattern before, but also match with the digits 0 to 9 and the "-", again one or more characters must be found "\." -- explicitly match the ".", a period without the backslash can match any single character otherwise "([a-zA-Z]{2,3})" -- match a subpattern containing 2 or 3 characters in the alpha character set "$" -- match to the end of the string.

Perl is also enhanced to take special modifiers that will affect the way the match is made. POSIX finds the first match and then finishes, whereas Perl finds "all" the matches before it returns.

The Pattern: text box -- It allows to enter the pattern string.

The Test String: text box -- It allows to enter the string in which the pattern is searched.

The Result: text box -- It shows up the result upon clicking the Test button, whether the pattern matched the string or not.

The Copy button -- It allows to copy the pattern string onto the clipboard, which can be pasted on to the editor.

The alnum button -- It allows to enter the alphanumeric pattern string in the Pattern string text box.

The alpha button -- It allows to enter the alphabetic pattern string in the Pattern string text box.

The digit button -- It allows to enter the numeric pattern string (In case of POSIX it is[:digit:], whereas it is "\d" in PERL) in the Pattern string text box.

The white button -- It allows to enter the whitespace pattern string (In case of POSIX it is[:blank:], whereas it is "\s" in PERL)in the Pattern string text box.

Following are the tables of symbols for both POSIX and PERL:

POSIX
alnum [:a-zA-Z0-9]
alpha [:a-zA-Z]
digit [:0-9]
white [:" " ]
PERL
alnum [a-zA-Z0-9]
alpha [a-zA-Z]
digit \d
white \s

[ << previous ] [ index ] [ next >> ]